<template>
  <div class="container">
    <div class="row">
        <ForumHeader/>
        <div style="margin: 80px;"></div>
        <el-table
            :data="UserData"
            style="width: 100%">
        <el-table-column
                prop="userid"
                label="用户id"
                width="180">
        </el-table-column>
        <el-table-column
                prop="username"
                label="用户姓名"
                width="180">
        </el-table-column>
        <el-table-column
                prop="userpassword"
                label="用户密码">
        </el-table-column>
        <el-table-column
                prop="useridentity"
                label="身份">
        </el-table-column>
        <el-table-column label="操作">
            <template slot-scope="scope">
                <el-button
                        size="mini"
                        type="danger"
                        @click="handleBanner(scope.row)">封禁</el-button>
            </template>
        </el-table-column>
    </el-table>
    <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="this.query.page"
            :page-sizes="[5, 10, 20, 30]"
            :page-size="this.query.size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="this.total">
    </el-pagination>

    <el-dialog title="封禁页面" :visible.sync="dialogFormVisible">
        <el-form :model="bannerform">
            <el-form-item label="封禁用户姓名" >
                <el-input v-model="bannerform.bannerusername" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="封禁操作管理员名" >
                <el-input v-model="bannerform.banneradminname" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="封禁时间">
                <el-date-picker
                v-model="bannerform.bannertime"
                type="datetime"
                placeholder="选择日期时间">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="封禁原因" >
                <el-input v-model="bannerform.bannerreason" autocomplete="off"></el-input>
            </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
            <el-button @click="dialogFormVisible = false">取 消</el-button>
            <el-button type="primary" @click="submitForm()">确 定</el-button>
        </div>
    </el-dialog>

    </div>
    <div class="row">
            <el-button type="success" @click="TOBannerList()" class="col-md-2 mx-auto" style="margin: 0 auto;">前往封禁列表</el-button>
        </div>
  </div>
</template>

<script>
import ForumHeader from './ForumHeader.vue'
export default {
    name:"AdminIndex",
    components:{ForumHeader},
    data() {
            return {
                UserData: [],
                total:0,
                query: {
                    page:1,
                    size:5,
                },
                dialogFormVisible: false,
                Userform: {
                    userid:'',
                    username:"",
                    userpassword:'',
                    useridentity:"",
                },
                bannerform:{
                    bannerid:"",
                    bannerusername:"",
                    banneradminname:"",
                    bannertime:"",
                    bannerreason:'',
                    bannerstatus:0
                }
            }
        },
    mounted() {
        this.getUserList();
    },
    methods:{
        getUserList(){
            this.axios.get('http://localhost:8001/login-user/getUserList',{
                params:{
                    page:this.query.page,
                    size:this.query.size,
                }
            }).then((resp)=>{
                this.UserData = resp.data.content.list;
                this.total = resp.data.content.total;
            })
            },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.query.size = val;
            this.getList();
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.query.page = val;
            this.getList();
        },
        TOBannerList(){
            this.$router.push({path:'/bannerList'});
        },
        handleBanner(row){
            this.bannerform.bannerusername = row.username
            this.Userform = row;
            this.dialogFormVisible = true;
        },
        submitForm(){
            this.axios.post('http://localhost:8001/banner/addbanner/',this.bannerform).then((resp)=>{
                let data = resp.data;
                if (data.success){
                    this.dialogFormVisible = false;
                    this.bannerform = {};
                    this.getUserList();
                    this.$message({
                        message:"操作成功",
                        type:'success'
                    });
                    this.changeuseridentity();
                }
            })
        },
        changeuseridentity(){
            this.Userform.useridentity = 3;
            this.axios.post('http://localhost:8001/login-user/saveUser/',this.Userform).then((resp)=>{
                console.log(this.Userform)
                let data = resp.data;
                if(data.success){
                    this.dialogFormVisible = false;
                    this.Register = {};
                    this.$message({
                        message: '恭喜你，操作成功',
                        type: 'success'
                    });
                }
            })
        }
    }
}
</script>

<style>

</style>